package com.heboan.hadoop.mr_homework;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class MyBean implements WritableComparable<MyBean> {
    private Integer n;

    public MyBean() {
    }

    public MyBean(Integer n) {
        this.n = n;
    }

    // 排序规则
    @Override
    public int compareTo(MyBean o) {
        return this.n.compareTo(o.getN());
    }

    // 序列化
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeInt(n);
    }

    // 反序列化
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.n = dataInput.readInt();
    }

    public Integer getN() {
        return n;
    }

    public void setN(Integer n) {
        this.n = n;
    }

    @Override
    public String toString() {
        return ""+n;
    }
}
